#pragma once

#include <vector>

#include "base/event_loop.h"
#include "ice_transport_channel.h"

namespace xrtc {

// ICE通道的代理    
class IceAgent : public sigslot::has_slots<> {
public:
    IceAgent(EventLoop* el, PortAllocator* allocator) : m_evl(el), m_allocator(allocator) {}
    ~IceAgent() = default;

    bool create_channel(EventLoop* el, const std::string& transport_name, IceCandidateComponent component);
    IceTransportChannel* getChannel(const std::string& transport_name, IceCandidateComponent component);

    void set_ice_parameters(const std::string& transport_name, IceCandidateComponent component, 
                            const IceParameters& ice_param);

    void set_remote_ice_params(const std::string& transport_name,
            IceCandidateComponent component,
            const IceParameters& ice_params);

    void gathering_candidate();

private:
    std::vector<IceTransportChannel*>::iterator _getChannel(const std::string& transport_name, 
        IceCandidateComponent component);

    void on_candidate_allocate_done(IceTransportChannel* channel,
            const std::vector<Candidate>& candidates);

public:
    sigslot::signal4<IceAgent*, const std::string&, IceCandidateComponent,
        const std::vector<Candidate>&> signal_candidate_allocate_done;           

private: 
    EventLoop* m_evl;
    std::vector<IceTransportChannel*> m_channels; // ice传输通道的集合
    PortAllocator* m_allocator;
};    

}